<template>
	<view class="header-bg-image header-bg">
		<view style="height: 50rpx;"></view>
		<view class="padding-20">
			<view class="margin-30-0 flex-around" @click="$tools.navigateBack()">
				<u-icon name="arrow-left" color="#333333" size="20"></u-icon>
				<view class="fontSize-18 color-000 flex1 text-center">会员签到</view>
				<view style="width: 40rpx;"></view>
			</view>
			<view class="header-view">
				<view class="header-view-left">
					<view class="header-title">签到积分</view>
					<view class="header-title1">{{userinfo.score}}</view>
				</view>
				<!-- <image class="header-image" src="../../static/sign-image.png" mode=""></image> -->
			</view>
			<view>
				<uni-calendar class="uni-calendar--hook" :selected="info.selected" :showMonth="false"
					@change="signInChange" />
			</view>
			<view class="btn30-967C5E-15ffffff flex-center margin-top150" @click="handleSign">签到</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {
					lunar: true,
					range: true,
					insert: false,
					selected: []
				},
				userinfo: {},
				time: ''
			}
		},
		onShow() {
			if (uni.getStorageSync('token')) {
				this.getData()
			}
		},
		onReady() {
			// console.log(uni.getStorageSync('signIn'))
			// this.info.selected = uni.getStorageSync('signIn')
			this.signInList()
		},
		methods: {
			// 获取个人信息
			getData() {
				this.$http.post(this.$api.user_info, {}, {
					token: true
				}).then(res => {
					if (res.code === 1) {
						this.userinfo = res.data
					}
				})
			},
			async handleSign(e) {
				// 模拟动态打卡
				let res = await this.$http.post(this.$api.sign_add, {}, {
					token: true
				})
				if(res.code ==1){
					this.$tools.toast('打卡成功')
				}
				this.signInList()
			},

			// 打卡列表
			async signInList() {
				this.info.selected = []
				let res = await this.$http.post(this.$api.sign_list, {
					page: 1,
					limit: 1000
				}, {
					token: true
				})
				this.info.selected = res.data.map(item => {
					return {
						date: item,
						info: "打卡"
					}
				})
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	// .uni-calendar-item--isDay{
	//     background-color: #967C5E;
	//     opacity: 0.8;
	//     color: #fff;
	// }
	// .uni-calendar--hook{
	// 	background-color: ;
	// }
	.calendar-title {
		font-size: 16px;
		color: #333333;
		padding-top: 20rpx;
	}

	.calendar-view {
		// background-color: #ffffff;
		padding: 20rpx;
	}

	.desc-title1 {
		font-weight: 400;
		font-size: 26rpx;
		color: #707070;
		margin-bottom: 10rpx;
	}

	.desc-title {
		font-weight: 500;
		font-size: 30rpx;
		color: #000000;
		margin-bottom: 20rpx;
	}

	.desc-view {
		margin-top: 20rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		padding: 30rpx;
	}

	.header-title2 {
		width: 140rpx;
		height: 46rpx;
		text-align: center;
		line-height: 46rpx;
		font-weight: 400;
		font-size: 24rpx;
		color: #D41011;
		background: #FFF1F1;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		border: 1rpx solid #D41011;
	}

	.header-title1 {
		font-weight: 500;
		font-size: 60rpx;
		color: #000000;
		margin-bottom: 10rpx;
	}

	.header-title {
		font-weight: 400;
		font-size: 28rpx;
		color: #333333;
		margin-bottom: 10rpx;
	}

	.header-view-left {
		display: flex;
		flex-direction: column;
	}

	.header-image {
		width: 270rpx;
		height: 220rpx;
		flex-shrink: 0;
	}

	.header-view {
		padding: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex: 1;
	}

	.bg {
		width: 100%;
		height: 100vh;
		// background: url('/static/sign-bg.png') no-repeat;
		background-size: 100% 100%;
	}
</style>